﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using ZWL.Common.Module;
using Model;
using System.Collections.Generic;

public partial class Left : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        literalNav.Text = this.GetHeader() + this.GetBody() + this.GetFooter();

    }

    private string GetFooter()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        return "</script>";
    }

    private string GetBody()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("var outlookbar=new outlook();");
        sb.Append("var t;");


        IList<ERPMenu> rights = Factory.getERPMenuDAL().ERPMenu_getByRoleId(getRoleId());
        foreach (ERPMenu right in rights)
        {
            sb.Append(GetFirstNav(right));
        }

        return sb.ToString();

    }
    /// <summary>
    /// 得到第一层节点
    /// </summary>
    /// <param name="right"></param>
    /// <returns></returns>
    private string GetFirstNav(ERPMenu right)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        IList<ERPMenu> rights = Factory.getERPMenuDAL().ERPMenu_getItemByRoleId(getRoleId(), right.MenuId);

        foreach (ERPMenu r in rights)
        {
            //t=outlookbar.addtitle('权限管理','系统设置',1);
            sb.AppendFormat("t=outlookbar.addtitle('{0}','{1}',1);", r.MenuName, right.MenuName);
            if (r.Right_type == "Folder")
            {
                sb.Append(GetTwoNav(r));//继续获取第二层菜单对象
            }
            else
            {
                //outlookbar.additem('调动审核',t,'/Web/arcArchive.do?op=toUpadate')
                sb.AppendFormat("outlookbar.additem('{0}',t,'{1}');", r.MenuName, r.WebUrl);
            }
        }

        return sb.ToString();

    }

    private string GetTwoNav(ERPMenu right)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        IList<ERPMenu> rights = Factory.getERPMenuDAL().ERPMenu_getItemByRoleId(getRoleId(), right.MenuId);
        foreach (ERPMenu r in rights)
        {
            sb.AppendFormat("outlookbar.additem('{0}',t,'{1}');", r.MenuName, r.WebUrl);
        }

        return sb.ToString();

    }

    private string GetHeader()
    {
        return "<script type='text/javascript'>";
    }
}
